package C_Paper;

public class C100_20 {
    public static void main(String[] args) {
        System.out.println(hj(5,4 ,7));
        System.out.println(hj(40,40 ,18));;
    }
    public static int hj(int m,int n,int k){
        int[][] x = new int[m][n];
        int num = n*m;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (sw(i)+sw(j) > k) {num--; x[i][j] = -1; continue;}
                int p = 4;
                if (i-1 < 0 || x[i-1][j] == -1) p--;
                if (i+1 >= m || x[i+1][j] == -1) p--;
                if (j-1 < 0 || x[i][j-1] == -1) p--;
                if (j+1 >= n || x[i][j+1] == -1) p--;
                if (p == 0) num--;
            }
        }
        return num;
    }
    public static int sw(int x){
        return x % 10 + x / 10;
    }
}
